<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <style>
        .headline-content {
            padding: 5px 10px;
            max-width: 680px !important;
            margin:0 auto;
        }

        .div-margin {
            margin-bottom: 5px;
        }

        .title {
            color: #141414;
            font-size: 18px;
        }

        .tags .tag {
            display: inline-block;
            border: solid 1px #A3A3A3;
            padding: 2px 9px;
            border-radius: 11px;
            color: #A3A3A3;
            font-size: 12px;
            margin-right: 4px;
            min-width: 12px;
            text-align: center;
        }

        .time {
            display: inline-block;
            color: #A3A3A3;
            font-size: 12px;
        }

        .content {
            color: #141414;
            font-size: 14px;
        }

        .not-found {
            position: absolute;
            width: 100%;
            text-align: center;
            top: 50%;
            margin-top: -10px;
        }

        .hide {
            display: none;
        }
    </style>
</head>
<body>
<div class="headline-content">
    <div class="title div-margin"></div>
    <div class="tags div-margin"></div>
    <div class="time div-margin"></div>
    <div class="content div-margin"></div>
    <div class="not-found hide">
        <span class="tip-msg">文章内容未找到</span>
    </div>
</div>

<script src="component/jquery/jquery.min.js"></script>
<script src="js/common.js"></script>
<script type="text/javascript">
    $(function () {
        var getUrlParameter = function getUrlParameter(sParam) {
            var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;

            for (i = 0; i < sURLVariables.length; i++) {
                sParameterName = sURLVariables[i].split('=');

                if (sParameterName[0] === sParam) {
                    return sParameterName[1] === undefined ? true : sParameterName[1];
                }
            }
        };
        $.getJsonData("/hycj/news/" + getUrlParameter("id")).done(function (result) {
            var headline = result.datas;

            $(".title").html(headline.title);
            if(headline.tag.length >0 ) {
                $(headline.tag.split(",")).each(function (index, tag) {
                    $(".tags").append(" <span class=\"tag\">" + tag + "</span>");
                });
            }
            $(".content").html(headline.content);
            var arr = headline.createTime.split(/[-:\/\s]/);
            var date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
            $(".time").html(dateStr(date.getTime()));
        });

        /**
         * 毫秒转换友好的显示格式
         * 输出格式：21小时前
         * @param  {[type]} time [description]
         * @return {[type]}      [description]
         */
        function dateStr(date) {
            //获取js 时间戳
            var time = new Date().getTime();
            //去掉 js 时间戳后三位
            time = parseInt((time - date) / 1000);

            //存储转换值
            var s;
            if (time < 60 * 10) {//十分钟内
                return '刚刚';
            } else if ((time < 60 * 60) && (time >= 60 * 10)) {
                //超过十分钟少于1小时
                s = Math.floor(time / 60);
                return s + "分钟前";
            } else if ((time < 60 * 60 * 24) && (time >= 60 * 60)) {
                //超过1小时少于24小时
                s = Math.floor(time / 60 / 60);
                return s + "小时前";
            } else {
                //超过24小时
                var date = new Date(date);
                return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
            }
        }
    });
</script>
</body>
</html>